home *** CD-ROM | disk | FTP | other *** search
- Path: gate.net!pslfl2-14
- From: bhutto@gate.net (William Hutto)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with stringcopy
- Date: 7 Jan 1996 09:44:52 GMT
- Organization: CyberGate, Inc.
- Message-ID: <4co4mk$1pqi@news.gate.net>
- References: <4clguu$9fs@eagle.novo.dk> <yewvimppjz5.fsf@hyll.idt.unit.no> <4cmafq$bm5@clarknet.clark.net>
- NNTP-Posting-Host: pslfl2-14.gate.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4cmafq$bm5@clarknet.clark.net>,
- eamick@clark.net (Eric Amick) wrote:
- >Amund Tveit (amundt@pvv.unit.no) wrote:
- >>[Morten Brun]
- >>
- >>| How do i do a partial stringcopy i.e. copy from a specific position in
- >>| a string and a certain numbers of bytes. I am looking for a function
- >>| like target = Stringcopy(source, startpos, length)
- >>
- >>You can try something like this :
- >>char *Stringcopy(char *source, int startpos, size_t length)
- >>{
- >> char tmpstring[SIZEBIGENOUGH];
- >> strncpy((char *)(source+startpos),tmpstring,length);
- >> return tmpstring;
- >>}
- >
- >This won't work as written; the first two arguments to strncpy() are
- >reversed. The cast is also unnecessary.
- >
-
- Seems like it's getting closer. Why have a separate function?
-
- strncpy(destination,&source[startpos],max_length);
-
- Bill
-
- "Whatcha got on?...Your mind?"
-